package com.chixing.controller;

import com.chixing.service.CarService;
import com.chixing.service.RentalCarService;
import com.chixing.util.ServerResponse;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.io.Serializable;
import java.util.Date;

/**
 * @author YHB
 * @date 2021/10/8  18:06
 */
@Controller

public class RentalCarController {
    @Autowired
    private RentalCarService rentalCarService;


    //多条件查询
    // car_rental/car/本田/-1/-1/-1/-1/1
    @GetMapping("car")
    @ResponseBody
    public ServerResponse getByConditions(@RequestParam("carBrandname") String carBrandname,
                                          @RequestParam("minCarCategoryStartprice") Double minCarCategoryStartprice,
                                          @RequestParam("maxCarCategoryStartprice") Double maxCarCategoryStartprice,
                                          @RequestParam("carMatic") String carMatic,
                                          @RequestParam("carSeatnum") Integer carSeatnum,
                                          @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                          @RequestParam("status") Integer status
    ) {

        /*System.out.println("carBrandname:"+carBrandname);
        System.out.println("minCarCategoryStartprice:"+minCarCategoryStartprice);
        System.out.println("maxCarCategoryStartprice:"+maxCarCategoryStartprice);
        System.out.println("carMatic:"+carMatic);
        System.out.println("carSeatnum:"+carSeatnum);
        System.out.println("pageNum:"+pageNum);*/


        if (pageNum == null) {
            System.out.println("pagenum =" + pageNum);
            pageNum = 1;
        }

        return rentalCarService.getByConditions(carBrandname, minCarCategoryStartprice, maxCarCategoryStartprice, carMatic, carSeatnum, pageNum, status);
    }

    //根据storeid查门店
    @GetMapping("ajax/store/{storeId}")
    @ResponseBody
    public ServerResponse getByStoreId(@PathVariable("storeId") Integer storeId) {
        return rentalCarService.getByStoreId(storeId);
    }

    //根据carid查车辆
    @GetMapping("ajax/car/{carId}")
    @ResponseBody
    public ServerResponse getByCarId(@PathVariable("carId") Integer carId) {
        return rentalCarService.getByCarId(carId);
    }

    @GetMapping("car/StoreAndDate")
    @ResponseBody
    public ServerResponse getCarByStoreAndDate(Integer storeId, Date getCarTime, String carBrandname, Double minCarCategoryStartprice,Double maxCarCategoryStartprice,
                                               String carMatic, Integer carSeatnum, Integer status) {
        return rentalCarService.getCarByStoreAndDate(storeId, getCarTime, carBrandname, minCarCategoryStartprice, maxCarCategoryStartprice,carMatic, carSeatnum, null, status);
    }


}
